<?php
namespace Weibo\Model;
use Common\Model\BaseModel;
class WeiboUserModel extends BaseModel {
	
	/**
	 * 获取用户列表根据用户ID集合
	 * @author	Baiyu
	 * @param	array		$user_ids
	 * @param	number		$offset
	 * @param	number		$limit
	 * @return	boolean|array
	 */
	public function getUserByIds($user_ids = array(), $offset = 0, $limit = 0){
		$return = array();
		
		if (is_array($user_ids) && !empty($user_ids)) {
			$this -> where(array('user_id' => array('IN', $user_ids)));
			
			if ($limit) {
				$this -> limit($offset, $limit);
			}
			
			$list = $this -> select();
			if (!empty($list)) {
				foreach ($list as $item) {
					$return[$item['user_id']] = $item;
				}
			} else {
				$return = $list;
			}
		}
		
		return $return;
	}
	
	/**
	 * 获取微博用户根据用户ID
	 * @param	number	$user_id	用户ID
	 * @param	boolean	
	 * @return	boolean|array|null
	 */
	public function getUserById($user_id, $merge_user = FALSE) {
		$return = array();
		
		if ($user_id) {
			$return = $this -> where(array('user_id' => $user_id)) -> find();
		}
		
		return $return;
	}
	
	/**
	 * 根据用户昵称获取用户ID
	 * @param	array|string	$nicknames	用户昵称
	 * @return	array|number
	 */
	public function getUseridByNicknames($nicknames = array(), $with_nickname = FALSE){
		$return = array();
		$where = array();
		$fields = 'user_id';
		
		if (is_array($nicknames) && !empty($nicknames)) {
			$where['nickname'] = array('IN', $nicknames);
		} elseif (is_string($nicknames)) {
			$where['nickname'] = $nicknames;
		}
		
		$with_nickname && $fields .= ',nickname';
		
		$where && $return = $this -> where($where) -> getField($fields);
		
		return is_string($nicknames) && !empty($return) ? reset($return) : $return;
	}
}
